package ${entity.getSiblingPackage("controller")};

import javax.annotation.Resource;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;

import wo.common.entity.WoPage;
import wo.common.exception.WoResultCode;
import wo.common.util.WoUtil;
import ${entity.getSiblingPackage("dto")}.${entity.entityName}Dto;
import wo.xsys.util.XSysConstant;
import ${entity.getSiblingPackage("service")}.${entity.entityName}Service;
import wo.xsys.vo.WoGridData;

/**
 * ${entity.entityCN}对应控制器
 * @author cailei
 */
@RestController
@RequestMapping(value = "/${entity.module}/${entity.entityNameLowerFirstChar}", produces = "application/json")
@SessionAttributes(names = XSysConstant.SESSION_USER)
public class ${entity.entityName}Controller {
	
	/**
	 * 引入日志打印框架.
	 */
	private final static Logger LOG = LogManager.getLogger(${entity.entityName}Controller.class);
	
	/**
	 * 注入${entity.entityName}Service.
	 */
    @Resource // @Autowired
	private ${entity.entityName}Service ${entity.entityNameLowerFirstChar}Service;
	
	/**
     * 查询${entity.entityCN}列表数据
     * @param searchContent 查询内容
     * @param selectedIds 列表中选中的${entity.entityCN}id，如果多个，以逗号隔开
     * @param start
     * @param limit
     * @return
     */
    @RequestMapping("/list")
    public WoGridData<${entity.entityName}Dto> list(String searchContent, String selectedIds, Long start, Long limit) {
    	WoPage<${entity.entityName}Dto> pageData = ${entity.entityNameLowerFirstChar}Service.getPageData(searchContent, WoUtil.splitIds(selectedIds), start, limit);
        return new WoGridData<${entity.entityName}Dto>(pageData.getRows(), pageData.getResults());
    }

    /**
     * 创建${entity.entityCN}
     * @param m
     * @return
     */
    @RequestMapping("/create")
    public WoResultCode create(${entity.entityName}Dto m) {
        ${entity.entityNameLowerFirstChar}Service.create(m);
        return WoResultCode.getSuccessCode();
    }

    /**
     * 删除${entity.entityCN}
     * @param selectedIds 列表中选中的${entity.entityCN}id，如果多个，以逗号隔开
     * @return
     */
    @RequestMapping("/delete")
    public WoResultCode delete(String selectedIds) {
        ${entity.entityNameLowerFirstChar}Service.delete(WoUtil.splitIds(selectedIds));
        return WoResultCode.getSuccessCode();
    }

    /**
     * 修改${entity.entityCN}
     * @param m
     * @return
     */
    @RequestMapping("/update")
    public WoResultCode update(${entity.entityName}Dto m) {
        ${entity.entityNameLowerFirstChar}Service.update(m);
        return WoResultCode.getSuccessCode();
    }

}
